<template>
	<view>
		<!--闪买-->
		<home :scrollY="scrollY" :scrollBottom="scrollBottom" :show="tabID==0?true:false" v-if="loadOn.home" />

		<!--闪卖-->
		<sell :scrollY="scrollY" :scrollBottom="scrollBottom" :show="tabID==1?true:false" v-if="loadOn.sell" @closeTap="sellCloseTap" />

		<!--购物车-->
		<cart  :show="tabID==2?true:false" v-if="loadOn.cart" ></cart>
		<!--我的-->
		<my :scrollY="scrollY" :scrollBottom="scrollBottom" :show="tabID==3?true:false" v-if="loadOn.my" />

		<!--底部导航-->
		<footer-tabbar :tabID='tabID' :msgDot='true' @tabTap='tabTap' />
	</view>
</template>

<script>
	//加载组件
	import home from '@/components/zaiui-common/view/home';
	import sell from '@/components/zaiui-common/view/sell';
	import my from '@/components/zaiui-common/view/my';
	import cart from '@/components/zaiui-common/view/my_cart';

	//固定组件
	import footerTabbar from '@/components/zaiui-common/footer/footer-tabbar';

	//工具函数
	import _tool from '@/static/zaiui/util/tools.js';
	
	export default {
		components: {
			home,
			sell,
			my,
			footerTabbar,
			cart
		},
		data() {
			return {
				loadOn: {
					home: true,
					sell: false,
					cart:false,
					my: false
				},
				scrollY: 0,
				scrollBottom: 0,
				tabID: 0,
				tabIndex: 0,
			}
		},
		onLoad(options) {
			this.tabTap(options.tabID)
		},
		onReady() {
			_tool.setBarColor(true);
		},
		methods: {
			tabTap(index) {
				this.tabIndex = this.tabID;
				if (index == 1 && !this.loadOn.sell) {
					this.loadOn.sell = true;
				}
				if (index == 2 && !this.loadOn.news) {
					this.loadOn.cart = true;
				}
				if (index == 3 && !this.loadOn.my) {
					this.loadOn.my = true;
				}
				this.tabID = index;
				//设置颜色
				if (index == 0) {
					_tool.setBarColor(false);
				}
				if (index == 2) {
					_tool.setBarColor(true);
				}
				if (index == 3) {
					_tool.setBarColor(false);
				}
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				});
			},
			sellCloseTap() {
				this.tabTap(this.tabIndex);
			},
		},
		onPageScroll(e) {
			this.scrollY = e.scrollTop;

		},
		onReachBottom(e) {
			let timestamp = new Date().getTime();
			this.scrollBottom = timestamp;
		},
	}
</script>

<style lang="scss">

</style>
